var data = {
    activities: [],
    pageNo: 0,
    pageSize: 10,
    count: 9999,
    refreshing: false
}

var vm = {
    data() {
        return data
    },
    computed: {
        noMoreActivity() {
            return this.activities.length >= this.count
        }
    },
    mounted() {
        if (this.pageNo == 0) this.loadMoreActivity()
    },
    methods: {
        loadMoreActivity(done) {
            if (!this.noMoreActivity || this.pageNo == 0) {
                this.pageNo++
                $ajax.activity.list({
                    userId: $store.state.user.userId,
                    pageNo: this.pageNo,
                    pageSize: this.pageSize
                }).then((res) => {
                    var { code, data } = res.data
                    if (code == 'S') {
                        if (this.pageNo > 1) {
                            this.activities.push(...data.list)
                        } else {
                            this.activities = data.list
                        }
                        this.count = data.count
                    } else {
                        this.pageNo--
                    }
                    done && done()
                    this.closeActivityLoad()
                }).catch(err => {
                    this.pageNo--
                    done && done()
                    this.closeActivityLoad()
                })
            }
        },
        goDetail(jumpUrl) {
            if (jumpUrl && jumpUrl.length > 0) window.location.href = jumpUrl
        },
        // 下拉刷新
        reLoadActivity(done) {
            this.pageNo = 0
            this.count = 99
            this.refreshing = true
            this.loadMoreActivity(done)
        },
        // 关闭加载操作
        closeActivityLoad() {
            this.refreshing = false
            this.$refs.activityScroller.infiniteDone()
            this.$refs.activityScroller.refreshDone()
        }
    },
    mixins: [$mixins.needLogin]
}

export default vm